<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\AppUsers;
use App\Models\Opinion;
use Illuminate\Http\Request;

class OpinionController extends Controller
{
    public function save(Request $request)
    {
        if (!$request->post('content', '')) {
            return $this->errors('-1', '请输入反馈意见');
        }
        $user = AppUsers::where(['api_token' => $request->post('token', '')])->first();
        if ($opinion = Opinion::create(['title' => '用户反馈', 'user_id' => $user->id, 'content' => $request->post('content')])) {
            return $this->success(200, '提交成功', $opinion->toArray());
        }
        return $this->errors('-1', '提交失败');
    }
}
